﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="/admin/plugins/bootstrap-table/bootstrap.min.css" />
    <link href="/admin/static/css/common.css" rel="stylesheet" />
    <script src="/admin/static/js/jquery.min.js"></script>
    <script src="/admin/plugins/layer/layer.js"></script>
    <script type="text/javascript">
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return decodeURIComponent(r[2]); return null; //返回参数值
        }
        $(function () {
            fetch("/Domains/get", {
                body: "Action=get&id=" + getUrlParam("rowid"),
                headers: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                method: "POST"
            })
              .then(function (response) {
                  if (response.ok) {
                      return response.json();
                  }
                  throw new Error('Network response was not ok.');
              })
              .then(function (data) {
                  if (data.sucess) {
                      $("#name").val(data.data.name);
                      $("#host").val(data.data.host);
                      $("#state").val(data.data.state);
                      $("#appid").val(data.data.appid);
                      $("#callback").val(data.data.callback);
                      $("#jkey").val(data.data.jkey);
                      $("#scope").val(data.data.scope);
                  }
                  else {
                      layer.alert(data.info);
                  }
              }).catch(error => console.log('Error:', error));
        });
        function submitData() {
            fetch("/Domains/save", {
                body: "Action=save&id=" + (getUrlParam("rowid")||0) +"&"+ $("#form1").serialize(),
                headers: {
                    "content-type": "application/x-www-form-urlencoded"
                },
                method: "POST"
            })
              .then(function (response) {
                  if (response.ok) {
                      return response.json();
                  }
                  throw new Error('Network response was not ok.');
              })
              .then(function (data) {
                  if (data.sucess) {
                      parent.closeLayer(true);
                  }
                  else {
                      layer.alert("保存失败");
                  }
              }).catch(error => console.log('Error:', error));
        }
    </script>
    <style type="text/css">
        .l-table-edit {
        }

        .l-table-edit-td {
            padding: 4px;
            vertical-align: middle;
        }

        .l-table-edit-td-area {
            vertical-align: top;
        }

        .l-button-submit, .l-button-reset {
            width: 80px;
            float: left;
            margin-left: 10px;
            padding-bottom: 2px;
        }

        .l-button-first {
            margin-left: 96px;
        }
    </style>
</head>
<body style="padding: 10px">
    <form id="form1">
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 100%;">
            <tr>
                <td align="right" class="l-table-edit-td">
                    公众号名称<span style="color: #f00;">[*]</span>:
                </td>
                <td align="left" class="l-table-edit-td">
                    <input class="form-control" name="name" type="text" maxlength="50" id="name" value="" style="width: 455px;" />
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td">
                    回调域名<span style="color: #f00;">[*]</span>:
                </td>
                <td align="left" class="l-table-edit-td">
                    <input class="form-control" name="host" type="text" id="host" value="" />
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">
                    公众号AppId<span style="color: #f00;">[*]</span>:
                </td>
                <td align="left" class="l-table-edit-td">
                    <input class="form-control" name="appid" type="text" id="appid" value="" />
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">
                    标识:
                </td>
                <td align="left" class="l-table-edit-td">
                    <input class="form-control" name="state" type="text" id="state" maxlength="300" value="" />
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">
                    回调地址:
                </td>
                <td align="left" class="l-table-edit-td">
                    <input class="form-control" name="callback" type="text" id="callback" maxlength="1000" value="" />
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">
                    回调参数:
                </td>
                <td align="left" class="l-table-edit-td">
                    <input class="form-control" name="jkey" type="text" id="jkey" maxlength="300" value="" />
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
            <tr>
                <td align="right" class="l-table-edit-td" valign="top">
                    授权方式:
                </td>
                <td align="left" class="l-table-edit-td">
                    <select name="scope" id="scope" class="form-control">
                        <option value="0">静默授权</option>
                        <option value="1">获取信息</option>
                    </select>
                </td>
                <td align="right" class="l-table-edit-td"></td>
                <td align="left" class="l-table-edit-td"></td>
            </tr>
        </table>
        <br />
        <input type="button" value="提交" style="margin-left:190px;" class="btn btn-danger btn-default" onclick="submitData();return false;" />
        <input type="reset" value="重置" class="btn btn-primary btn-default" />
        <input type="button" value="关闭" class="btn btn-white" onclick="parent.layer.closeAll();" />
    </form>
</body>
</html>
